package thread;

import java.util.*;

public class SyncDemo5 {
    public static void main(String[] args) {
        //List<Integer> a=new ArrayList<>();
        List<Integer> a=new LinkedList<>();
        //Set<Integer> a=new HashSet<>();
        List<Integer> b=Collections.synchronizedList(a);
        List<Integer> c=Collections.synchronizedList(new ArrayList<>());
        Thread t1=new Thread(){
            public void run() {
                for (int i=0;i<1000;i++){
                    a.add(i);
                }
            }
        };
        Thread t2=new Thread(){
            public void run() {
                for (int i=0;i<1000;i++){
                    a.add(i);
                }
            }
        };
        t1.start();
        t2.start();
        try {
            Thread.sleep(1);
        } catch (InterruptedException e) {

        }
        System.out.println(a.size());
        System.out.println(a);
    }
}
